/**
 * 
 */
package org.perfect.batch.configuration;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;

/**
 * @author billmse
 *
 */
public class SimpleShardingAlgorithm implements HintShardingAlgorithm<String> {

	@Override
	public Collection<String> doSharding(Collection<String> availableTargetNames,
			HintShardingValue<String> shardingValue) {
		Collection<String> result = new ArrayList<>();
		for (String name : availableTargetNames) {
			for (String value : shardingValue.getValues()) {
				if (name.endsWith(value)) {
					result.add(name);
				}
			}
		}
		return result;
	}

}
